package cn.com.ejiakanghu.task;


import cn.com.ejiakanghu.service.EnterpriseWeChatService;
import org.linlinjava.litemall.core.task.Task;
import org.linlinjava.litemall.core.util.BeanUtil;
import org.linlinjava.litemall.db.dao.AgedmallTakeOrderRecordMapper;
import org.linlinjava.litemall.db.domain.AgedmallTakeOrderRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author wj
 * @date 2021/10/19 16:24
 */
public class RefusedOrderTask extends Task {
    private Logger logger = LoggerFactory.getLogger(RefusedOrderTask.class);
    private Integer takeOrderId=-1;
    private String responseCode="";
    public RefusedOrderTask(Integer takeOrderId, long delayInMilliseconds) {
        super("TakeOrder-"+takeOrderId, delayInMilliseconds);
        this.takeOrderId = takeOrderId;
    }

    public RefusedOrderTask(Integer takeOrderId) {
        super("TakeOrder-"+takeOrderId, 10 * 60 * 1000);
        this.takeOrderId = takeOrderId;
    }

    public RefusedOrderTask(Integer takeOrderId, String responseCode) {
        super("TakeOrder-"+takeOrderId, 10 * 60 * 1000);
        this.takeOrderId = takeOrderId;
        this.responseCode = responseCode;
    }


    @Override
    public void run() {
        logger.info("企业微信超时拒绝逻辑开始处理:{}",takeOrderId);

        AgedmallTakeOrderRecordMapper takeOrderRecordMapper = BeanUtil.getBean(AgedmallTakeOrderRecordMapper.class);
        EnterpriseWeChatService enterpriseWeChatService = BeanUtil.getBean(EnterpriseWeChatService.class);
        AgedmallTakeOrderRecord agedmallTakeOrderRecord = takeOrderRecordMapper.selectByPrimaryKey(takeOrderId.longValue());
        if(agedmallTakeOrderRecord.getState()==1){
            //调用超时拒绝方法
            enterpriseWeChatService.refused(takeOrderId.longValue(),true,responseCode);
        }
        logger.info("企业微信超时拒绝逻辑处理完成:{}",takeOrderId);
    }
}
